<?php
require_once(dirname(dirname(dirname(__FILE__))) . '/app.php');

need_manager();
$now = time();
$condition = array(
	"end_time > {$now}",
);

if($_GET['position']){
	$condition['position'] = $_GET['position'];
}
if($_GET['city_id']){
	$condition['city_id'] = $_GET['city_id'];
}

$count = Table::Count('page_ad', $condition);
list($pagesize, $offset, $pagestring) = pagestring($count, 20);

$ads = DB::LimitQuery('page_ad', array(
	'condition' => $condition,
	'order' => 'ORDER BY id DESC',
	'size' => $pagesize,
	'offset' => $offset,
));
$cities = Table::Fetch('category', Utility::GetColumn($ads, 'city_id'));

$selector = 'index';
include template('manage_ad_index');
